//
//  BVMyBaskListViewController.m
//  duobao
//
//  Created by YYKJ on 2017/7/15.
//  Copyright © 2017年 YYKJ. All rights reserved.
//  我的晒单

#import "BVMyBaskListViewController.h"
#import "BVCommunityCell1.h"
#import "DemoVC7Model.h"
#import "UITableView+SDAutoTableViewCellHeight.h"
#import "BVPublishedViewController.h"
#import "BVCommunityDetailViewController.h"

#define BUY_MYBASKLIST_TAB_CELL1 @"BVMyBaskListCell1"
@interface BVMyBaskListViewController ()<UITableViewDelegate ,UITableViewDataSource>

@property (nonatomic ,strong) UITableView      *tabView;
@property (nonatomic, strong) NSMutableArray *modelsArray;

@end

@implementation BVMyBaskListViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.navigationItem setTitle:@"幸运社区"];
    [self setNav];
    
    [self creatModelsWithCount:20];
    [self.view addSubview:self.tabView];
    
}

-(void)setNav{
    
    UIButton *rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [rightBtn setFrame:CGRectMake(0, 10, 26, 28)];
    [rightBtn setBackgroundImage:[UIImage imageNamed:@"fabiao"] forState:UIControlStateNormal];
    [rightBtn addTarget:self action:@selector(showRight:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem* rightBarBtn = [[UIBarButtonItem alloc] initWithCustomView:rightBtn];
    [self.navigationItem setRightBarButtonItem:rightBarBtn];
}

#pragma mark - 导航栏右侧按钮弹出视图
- (void)showRight:(UIButton *)btn{
    
    BVPublishedViewController *Published = [[BVPublishedViewController alloc]init];
    ROOTNAVPUSH(Published, YES);
}

#pragma mark -
#pragma mark - UITableViewDelegate,UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return 10;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    DemoVC7Model *demoVC14Modelodel = self.modelsArray[indexPath.row];
    
    return [self.tabView cellHeightForIndexPath:indexPath model:demoVC14Modelodel keyPath:@"model" cellClass:[BVCommunityCell1 class] contentViewWidth:ScreenW];
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    BVCommunityCell1 *cell = [tableView dequeueReusableCellWithIdentifier:BUY_MYBASKLIST_TAB_CELL1];
    cell.model = self.modelsArray[indexPath.row];
    return cell;
    
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    BVCommunityDetailViewController *communityDetailVC = [[BVCommunityDetailViewController alloc]init];
    ROOTNAVPUSH(communityDetailVC, YES);
}

-(UITableView *)tabView{
    if (!_tabView) {
        self.tabView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, ScreenW, ScreenH-64) style:UITableViewStylePlain];
        [self.tabView setDelegate:self];
        [self.tabView setDataSource:self];
        [self.tabView setBackgroundColor:[UIColor clearColor]];
        [self.tabView setShowsVerticalScrollIndicator:NO];
        [self.tabView setRowHeight:50];
        [self.tabView registerClass:[BVCommunityCell1 class] forCellReuseIdentifier:BUY_MYBASKLIST_TAB_CELL1];
    }
    return _tabView;
}

- (void)creatModelsWithCount:(NSInteger)count
{
    if (!_modelsArray) {
        _modelsArray = [NSMutableArray new];
    }
    
    NSArray *iconImageNamesArray = @[@"9358d",
                                     @"9358d",
                                     @"9358d",
                                     @"9358d",
                                     @"9358d",
                                     @"9358d",
                                     @"9358d",
                                     @"9358d",
                                     @"9358d"
                                     ];
    
    
    NSArray *textArray = @[@"当你的 a期处于这种模式下，否则在大屏上会显得字大，内容少，容易遭到用户投诉。但是建议不要长期处于这种模式下，否则在大屏上会显得字大，内容少，容易遭到用户投诉。",
                           @"然后等比例拉则在大屏上会显得字大长期处于这种模式下，否则在大屏上会显得字大，内容少这种情况下对界面不会",
                           @"长期处于容少，容易遭到用户投诉。",
                           @"但是建议不处于这种模式下，否则在大屏上会显得字大，内容少，容易遭到用户投诉。",
                           @"屏幕宽度返，否显，容易遭到用户投诉。但是建议不要长期处于这种模式下，否则在大屏上会显得字大，内容少，容易遭到用户投诉。"
                           ];
    
    for (int i = 0; i < count; i++) {
        
        int nameRandomIndex = arc4random_uniform(5);
        
        DemoVC7Model *model = [DemoVC7Model new];
        model.title = textArray[nameRandomIndex];
        model.iconImagePath = iconImageNamesArray[arc4random_uniform(9)];
        
        // 模拟“有或者无图片”
        int random = arc4random_uniform(1);
        if (random <= 8) {
            NSMutableArray *temp = [NSMutableArray new];
            
            int randomImagesCount = arc4random_uniform(9);
            for (int i = 0; i < randomImagesCount; i++) {
                int randomIndex = arc4random_uniform(9);
                NSString *text = iconImageNamesArray[randomIndex];
                [temp addObject:text];
            }
            
            model.imagePathsArray = [temp copy];
        }
        
        [self.modelsArray addObject:model];
    }
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}


@end
